# coding:utf-8
"""
Author: 11203
Date:  14:52
Name: send_utils
"""
import smtplib
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formataddr
from common.utils import EMAIL_ADDR, POP3_SEQ, SMTP_SSL_HOST, SMTP_SSL_PORT


# 发送邮件信息
# :param message: 要发送的邮件信息
# :param emailno: 发送目标EMAIL地址
# :param title: 邮件标题
# :param sub_title: 邮件副标题
def email_send(message: str, emailno: str, title: str = '标题', sub_title: str = '发送给我自己的邮件') -> dict:
    content_html = message
    mime_multipart = MIMEMultipart()
    mime_multipart['Subject'] = Header(title, 'utf-8')
    mime_multipart['From'] = formataddr((str(Header(sub_title, 'utf-8')), EMAIL_ADDR))
    mime_multipart.attach(MIMEText(content_html, 'html', 'utf-8'))
    smtp_ssl = smtplib.SMTP_SSL(SMTP_SSL_HOST, SMTP_SSL_PORT)
    smtp_ssl.login(user=EMAIL_ADDR, password=POP3_SEQ)
    # 发送HTML邮件
    senderrs = smtp_ssl.sendmail(EMAIL_ADDR, emailno, mime_multipart.as_string())
    return senderrs


# 发送短信
# :param message: 要发送的信息
# :param phoneno: 发送目标手机号
def phone_send(message: str, phoneno: str):
    pass